package com.codingfuture.web.controller;


import com.codingfuture.entity.Course;
import com.codingfuture.service.CourseService;
import com.codingfuture.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/courses")
    public Result list() {
        List<Course> list = courseService.list();
        return Result.ok(list);
    }

    @PostMapping("/course")
    public Result add(Course course) {
        int i = courseService.add(course);
        if (i > 0) {
            return Result.ok();
        } else {
            return Result.err();
        }
    }
}
